import { BaseModel } from '@/common/base/base.model';
import { Column, Entity, Index, ManyToOne, JoinColumn } from 'typeorm';
import { UserModel } from '@/module/user/user.model';
import { BooleanNumber } from "common/utils/data";

@Entity('MESSAGE', {
  synchronize: false,
}) // 系统消息
@Index('MESSAGE.user_uuid&is_read', ['userUuid', 'isRead'])
export class MessageModel extends BaseModel {
  @Column({
    comment: '接收用户uuid',
    type: 'uuid',
  })
  userUuid: string;
  @ManyToOne(() => UserModel, {
    createForeignKeyConstraints: false,
  })
  @JoinColumn({
    name: 'user_uuid',
    referencedColumnName: 'uuid',
  })
  user: UserModel;

  @Column({
    comment: '是否已读（1：已读，0：未读）',
    type: 'smallint',
    default: BooleanNumber.false,
  })
  @Index('MESSAGE.is_read')
  isRead: BooleanNumber;

  @Column({
    comment: '回复内容',
    type: 'varchar',
    length: 250,
  })
  content: string;
}
